home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / art&graf.ix / art-0039 / source / degascon.mod < prev    next >
Text File  |  1997-04-16  |  26KB  |  772 lines

  1. MODULE DegasConvert;
  2.  
  3. (*--------------------------------------------------------------------*)
  4. (*                                                                    *)
  5. (*   The program was completely re-written in August 1987 to use      *)
  6. (*   modules more effectively and use the colour palette information  *)
  7. (*   when converting pictures to hi-resolution.                       *)
  8. (*                                                                    *)
  9. (*   This module is the high-level control logic for the program.     *)
  10. (*   This module will respond to all messages from GEM and pass       *)
  11. (*   control to the appropriate routines. It will look after the      *)
  12. (*   menu. It will also deal with initialisation and termination.     *)
  13. (*                                                                    *)
  14. (*   When   Ver  Who  Why                                             *)
  15. (* -------- ---- ---  ---------------------------                     *)
  16. (* 17/ 9/89 2.04 LGM  Change number of blocks allocated depending     *)
  17. (*                    on free memory.                                 *)
  18. (*                    Reset palette frequently.                       *)
  19. (*                                                                    *)
  20. (* 25/ 8/89 LGM : Added Image selection from menu.                    *)
  21. (*                                                                    *)
  22. (*   Version 2.01                 November 1988   L.G. Miller         *)
  23. (*                                :- '.IMG' Processing.               *)
  24. (*                                                                    *)
  25. (*   Version 2.00                 July  1988      L.G. Miller         *)
  26. (*                                :- split up menu processing.        *)
  27. (*                                   add new options.                 *)
  28. (*                                   add sub image selection          *)
  29. (*                                April 1988      L.G. Miller         *)
  30. (*                                April 1987      L.G. Miller         *)
  31. (*                                                                    *)
  32. (*   Medium res bug fixed in      June  1987      L.G. Miller         *)
  33. (*--------------------------------------------------------------------*)
  34.  
  35.  
  36.  
  37. (* IMPORT  Trace; *)   
  38.  
  39. FROM    DCGlobal        IMPORT  LowRes, MedRes, HiRes,
  40.                                 HiResMaxX, HiResMaxY,
  41.                                 PrintPalette,
  42.                                 PrinterTypes,
  43.                                 PictureImage,
  44.                                 PrintImage,
  45.                                 DegasPicture,
  46.                 BITSPERWORD,
  47.                 TheWindow;
  48.  
  49. FROM    DCPrint         IMPORT  SetPrinterToUse,
  50.                                 PrintHiResPicture;
  51.  
  52. FROM    DCScreen        IMPORT  DisplayPicture;
  53.  
  54.  
  55. FROM    DCDAbout        IMPORT  DoAboutDialog;
  56.  
  57. FROM    DCDPalette      IMPORT  DoPaletteDialog,
  58.                                 DoPixelDialog;
  59.  
  60. FROM    DCDPrintImage   IMPORT  DoImageDialog;
  61.  
  62. FROM    DCSelImg        IMPORT  DoMedResSelectImage,
  63.                                 DoHiResSelectImage;
  64.  
  65. FROM    DCConvrt        IMPORT  ConvertDegasToHiRes,
  66.                                 ClearPicture,
  67.                                 SetLowResDefaultPrintPalette,
  68.                                 SetMedResDefaultPrintPalette;
  69.  
  70. FROM    DCCnvImg    IMPORT  ConvertToImage;
  71.  
  72.  
  73. FROM    DCFileIO        IMPORT  LoadDegasFile,
  74.                                 SaveDegasFile,
  75.                                 SaveImageFile;
  76.  
  77.  
  78. FROM    SYSTEM          IMPORT  ADDRESS, ADR;
  79.  
  80. FROM    Storage        IMPORT  ALLOCATE, DEALLOCATE, Cleanup, Available,
  81.                 MaxBlocks, LargestBlock; 
  82.  
  83. FROM    Bios            IMPORT  setColor;
  84.  
  85. FROM    GemDos        IMPORT  Malloc;
  86.  
  87. FROM    Strings         IMPORT  String,
  88.                                 Assign,
  89.                                 Concat;
  90.  
  91.  
  92. FROM    Resource        IMPORT  Objects,
  93.                 rsrc_load,
  94.                                 rsrc_free,
  95.                                 rsrc_gaddr;
  96.  
  97. IMPORT  Object;
  98.  
  99. FROM    MenuLib         IMPORT  menu_bar,
  100.                                 menu_ienable,
  101.                                 menu_tnormal,
  102.                  menu_icheck;
  103.  
  104. IMPORT  Forms;
  105.  
  106. IMPORT  Graphics;
  107.  
  108. IMPORT  Event;
  109.  
  110. IMPORT  Window;
  111.  
  112. (* INCLUDE FOR  ManyWindows ; *)
  113.  
  114. FROM Window IMPORT
  115.     Components,
  116.       (* =(AESWNU1,AESWNU2,AESWNU3,AESWNU4, (*top 4 bits unused *)
  117.             HSLIDE,      (*horizontal slider*)
  118.             RTARROW,     (*right arrow*)
  119.             LFARROW,     (*left arrow*)
  120.             VSLIDE,    (*vertical slider*)
  121.             DNARROW,    (*down arrow*)
  122.             UPARROW,    (*up arrow*)
  123.             RESIZE,    (*re-size box*)
  124.             INFO,    (*information line*)
  125.             MOVE,    (*move box*)
  126.             FULL,    (*full box*)
  127.             CLOSE,    (*close box*)
  128.             NAME);    (*title bar with name*)  *)
  129.     ComponentSet;
  130.  
  131. FROM    ManyWindows     IMPORT
  132.     XYWHRect,
  133.     CornersRect,
  134.  
  135.     WindowStates,     (* = ( open, full, topped );     *)
  136.         WindowSSet,       (*  = SET OF WindowStates;    *)
  137.  
  138.     WindowPtr,    (*  = POINTER TO AWindow;    *)
  139.  
  140.         AWindow,    (*  = RECORD
  141.              Handle      : INTEGER; (* The AES window handle *)
  142.              State      : WindowSSet;
  143.              Outer,
  144.              Workarea,
  145.          PrevSize     : WindowCoordinate;
  146.              Components : ComponentSet;
  147.              Font         : FontData;                      
  148.          Title        : String;
  149.            END;  (* Window *)         
  150.  
  151. VAR    *)
  152.   AESApplId,     
  153.   VDIHandle, 
  154.   ScreenResolution,
  155.                ShowAlert,
  156.                            StartApplication, 
  157.                            CreateAWindow,
  158.                            SetAWindowTitle,
  159.                            OpenAWindow,
  160.                            ClearAWindow,
  161.                            CloseAWindow,
  162.                            DeleteAWindow,
  163.                            TerminateApplication,
  164.  
  165. (* various conversion / translation utilities *)
  166.                            ToXYWHRect,
  167.                            ToCornersRect,
  168.                            QueryIntersect,
  169.                            GetWindowHandle,
  170.                            GetWindowPtr,
  171.                            BeginScreenUpdate,
  172.                            EndScreenUpdate, 
  173.                            ShowMouse,
  174.                            HideMouse;
  175. (* END ManyWindows.    *)
  176.  
  177. (*----------------------------------------------------------------------*)
  178. (* Resource file object numbers                                         *)
  179. (*----------------------------------------------------------------------*)
  180. FROM Dcrsc          IMPORT   menu,
  181.                              deskmenu, mabout, 
  182.  
  183.                              filemenu,
  184.                                  mfload, mfsave, mfimage, 
  185.                                  mfquit,
  186.  
  187.                              prntmenu,
  188.                                  mpprint, mpsize, 
  189.  
  190.                              picmenu,
  191.                                  mpicpat, mpiccnv, 
  192.  
  193.                              imgmenu,
  194.                      mimgsel,
  195.  
  196.                              prtrmenu,
  197.                                  mpmx80, mpfx80, mplq80;
  198.  
  199. (*----------------------------------------------------------------------*)
  200. (* -------------------- END OF IMPORTS -------------------------------- *)
  201. (*----------------------------------------------------------------------*)
  202.  
  203.  
  204. (*----------------------------------------------------------------------*)
  205. (*         G L O B A L      C O N S T A N T S                           *)
  206. (*----------------------------------------------------------------------*)
  207.  
  208. CONST
  209.     CVersionString = 'Version 2.04 September 1989';
  210.  
  211.     CResourceFilename = 'DCRSC.RSC';
  212.  
  213.     HourGlass    =  2;
  214.     Arrow       =  0;
  215.  
  216. (*----------------------------------------------------------------------*)
  217. (*         > > >   G L O B A L     V A R I A B L E S    < < <           *)
  218. (*----------------------------------------------------------------------*)
  219. VAR
  220.   TheInPicture,
  221.   TheOutPicture    : DegasPicture;
  222.  
  223.   ThePrintPalette       : PrintPalette;
  224.  
  225.   ThePictureImage       : PictureImage;
  226.   ThePrintImage         : PrintImage;
  227.  
  228.   FileLoaded            : BOOLEAN;
  229.  
  230.   MenuTreePtr           : ADDRESS;
  231.  
  232.   ScreenPalette         : ARRAY [ 0 .. 15 ] OF INTEGER;
  233.  
  234.   PictureFilename       : String; (* used for window title *)
  235.  
  236.   DummyWord1        : CARDINAL; (* force word boundary *)
  237.  
  238. (* dummy variables - saves having to keep declaring 'em *)
  239.   dumc  : CARDINAL;
  240.   dumi  : INTEGER;
  241.   dumf  : BOOLEAN;
  242.   dumlc : LONGCARD;
  243.  
  244.  
  245.  
  246. PROCEDURE SetPalette;
  247.   BEGIN
  248.     IF ScreenResolution = MedRes THEN
  249.        dumc := setColor(777H,0); (* white *)
  250.        dumc := setColor(555H,1); (* grey  *)
  251.        dumc := setColor(333H,2); (* grey  *)
  252.        dumc := setColor(000H,3); (* black *)
  253.     END;
  254.   END SetPalette;
  255.  
  256.  
  257. (*----------------------------------------------------------------------*)
  258. (* Process Left Button Event                                            *)
  259. (*----------------------------------------------------------------------*)
  260. PROCEDURE HandleButtonEvent ( x, y, button : CARDINAL );
  261.  
  262.   BEGIN
  263.     IF ( y <= TheWindow^.Workarea.Y ) THEN
  264.       RETURN
  265.     END;
  266.  
  267.     IF FileLoaded THEN
  268.       IF TheInPicture.resolution # HiRes THEN
  269.          DoPixelDialog ( TheInPicture,
  270.                          x, y, ScreenResolution,
  271.                          ThePrintPalette );
  272.       ELSE
  273.          dumi := ShowAlert('Hi-res pic!',1,1);
  274.       END;
  275.  
  276.     ELSE
  277.        dumi := ShowAlert('NO Picture loaded',1,1);
  278.     END;
  279.  
  280.   END HandleButtonEvent;
  281.  
  282.  
  283. (*----------------------------------------------------------------------*)
  284. (* Process Escape Key Event - start selection of sub image.             *)
  285. (* Uses Global Variables!                                               *)
  286. (* Set Print Image to same size as picture image, i.e. no scaling       *)
  287. (*----------------------------------------------------------------------*)
  288. PROCEDURE SelectImage;
  289.   VAR pi : PictureImage;
  290.  
  291.   BEGIN
  292.     IF NOT FileLoaded THEN
  293.        dumi := ShowAlert('NO Picture loaded',1,1);
  294.        RETURN
  295.     END;
  296.  
  297.     pi := ThePictureImage;
  298.     (*  remove everything from the screen *)
  299.     dumc := menu_bar( MenuTreePtr, FALSE );
  300.     CloseAWindow(TheWindow);
  301.  
  302.     IF ScreenResolution = MedRes THEN
  303.        DoMedResSelectImage( ThePictureImage,
  304.                             TheOutPicture.HiResPicture );
  305.     ELSE
  306.        DoHiResSelectImage( ThePictureImage,
  307.                            TheOutPicture.HiResPicture );
  308.     END;
  309.  
  310.     IF ( pi.StartX  # ThePictureImage.StartX )
  311.     OR ( pi.StartY  # ThePictureImage.StartY )
  312.     OR ( pi.Width   # ThePictureImage.Width  )
  313.     OR ( pi.Height  # ThePictureImage.Height ) THEN
  314.        ThePrintImage.Width  := ThePictureImage.Width;
  315.        ThePrintImage.Height := ThePictureImage.Height;
  316.     END;
  317.  
  318.     (*  reshow everything  *)
  319.     dumc := menu_bar( MenuTreePtr, TRUE );
  320.     OpenAWindow(TheWindow);
  321.     ClearAWindow(TheWindow);
  322.     DisplayPicture( TheOutPicture.HiResPicture);
  323.   END SelectImage;
  324.  
  325.  
  326. (*----------------------------------------------------------------------*)
  327. (* Process Escape Key Event - start selection of sub image.             *)
  328. (* Uses Global Variables!                                               *)
  329. (* Set Print Image to same size as picture image, i.e. no scaling       *)
  330. (*----------------------------------------------------------------------*)
  331. PROCEDURE HandleEscKeyEvent;
  332.  
  333.   BEGIN
  334.     IF NOT FileLoaded THEN
  335.        dumi := ShowAlert('NO Picture loaded',1,1);
  336.        RETURN
  337.  
  338.     ELSE
  339.        SelectImage;
  340.     END;
  341.      
  342.  END HandleEscKeyEvent;
  343.  
  344.  
  345. (*----------------------------------------------------------------------*)
  346. (* Load a picture file.                                                 *)
  347. (*----------------------------------------------------------------------*)
  348. PROCEDURE ProcessLoadRequest;
  349.   BEGIN
  350.     IF LoadDegasFile( TheInPicture,
  351.                       PictureFilename ) THEN
  352.        SetPalette;
  353.        FileLoaded := TRUE;
  354.        SetAWindowTitle( TheWindow, PictureFilename );
  355.        IF TheInPicture.resolution = LowRes THEN
  356.           SetLowResDefaultPrintPalette(TheInPicture.LowPalette,
  357.                                        ThePrintPalette );
  358.  
  359.        ELSE
  360.           SetMedResDefaultPrintPalette( TheInPicture.MedPalette,
  361.                                         ThePrintPalette );
  362.        END;
  363.        WITH ThePictureImage DO
  364.           StartX := 0;
  365.           StartY := 0;
  366.           Width  := HiResMaxX + 1;
  367.           Height := HiResMaxY + 1;
  368.        END; (* with *)
  369.        WITH ThePrintImage DO
  370.           StartCharX := 5;
  371.           StartCharY := 5;
  372.           Width  := HiResMaxX + 1;
  373.           Height := HiResMaxY + 1;
  374.           QueryLandscapePrint := FALSE;
  375.        END; (* with *)
  376.        dumc := Graphics.graf_mouse(HourGlass, NIL);
  377.        ShowMouse;
  378.        ConvertDegasToHiRes ( TheInPicture,
  379.                              TheOutPicture,
  380.                              ThePrintPalette );
  381.        dumc := Graphics.graf_mouse(Arrow,NIL);
  382.        HideMouse;
  383.     END; (* if *)
  384.     DisplayPicture( TheOutPicture.HiResPicture);
  385. END ProcessLoadRequest;
  386.  
  387.  
  388. (*----------------------------------------------------------------------*)
  389. (*  Change current print palette if changed, convert picture            *)
  390. (*----------------------------------------------------------------------*)
  391. PROCEDURE ModifyPrintPalette ( VAR inpicture,
  392.                                    outpicture : DegasPicture;
  393.                                VAR pp         : PrintPalette );
  394.   VAR tempp : PrintPalette;
  395.   BEGIN
  396.     tempp := pp;
  397.     IF DoPaletteDialog( tempp, inpicture.resolution ) THEN
  398.        pp := tempp;
  399.        dumc := Graphics.graf_mouse(HourGlass, NIL);
  400.        ConvertDegasToHiRes( inpicture, outpicture, pp );
  401.        dumc := Graphics.graf_mouse(Arrow, NIL);
  402.     END;
  403.   END ModifyPrintPalette;
  404.  
  405.  
  406. (*----------------------------------------------------------------------*)
  407. (* Convert portion of picture to IMG format & save it                   *)
  408. (*----------------------------------------------------------------------*)
  409. PROCEDURE SaveImage( VAR OutPic   : DegasPicture;
  410.                      VAR PicImage : PictureImage );
  411.   CONST CIMGBufferSize = LONGCARD(40000);
  412.  
  413.   VAR outlen : CARDINAL;
  414.       IMGBuffer : ADDRESS;
  415.   BEGIN
  416.     IF (PicImage.Width  = 0)
  417.     OR (PicImage.Height = 0) THEN
  418.       dumi := ShowAlert('NO Image Selected',1,1);
  419.       RETURN;
  420.     END;
  421.  
  422.     IF NOT Available(CIMGBufferSize) THEN    
  423.       dumi := ShowAlert('NO Room for image buffer',1,1);
  424.       RETURN;
  425.     END;
  426.     ALLOCATE(IMGBuffer, CIMGBufferSize);
  427.     ConvertToImage( PicImage,
  428.                     OutPic.HiResPicture,
  429.                     outlen,
  430.                     IMGBuffer );
  431.  
  432.     IF NOT SaveImageFile( outlen, IMGBuffer ) THEN END;
  433.     DEALLOCATE(IMGBuffer, CIMGBufferSize);
  434.   END SaveImage;
  435.  
  436.  
  437. (*----------------------------------------------------------------------*)
  438. (* Tell print module which printer is connected.                        *)
  439. (*----------------------------------------------------------------------*)
  440. PROCEDURE ChangePrinterSelected ( menuitem : INTEGER ) ;
  441.   CONST   check = TRUE;
  442.         nocheck = FALSE;
  443.   BEGIN
  444.     dumc := menu_icheck(MenuTreePtr, mpmx80, nocheck);
  445.     dumc := menu_icheck(MenuTreePtr ,mpfx80, nocheck);
  446.     dumc := menu_icheck(MenuTreePtr ,mplq80, nocheck);
  447.  
  448.     CASE menuitem OF
  449.       mpmx80  : dumc := menu_icheck(MenuTreePtr, mpmx80, check);
  450.                 SetPrinterToUse( EpsonMX80 );               |
  451.  
  452.       mpfx80  : dumc := menu_icheck( MenuTreePtr, mpfx80, check );
  453.                 SetPrinterToUse( EpsonFX80 );               |
  454.  
  455.       mplq80  : dumc := menu_icheck( MenuTreePtr, mplq80, check );
  456.                 SetPrinterToUse( EpsonLQ80 );               |
  457.     END; 
  458.   END ChangePrinterSelected ;
  459.  
  460.  
  461. (*----------------------------------------------------------------------*)
  462. (*  Each sub-menu has its own procedure                                 *)
  463. (*----------------------------------------------------------------------*)
  464.  
  465.  
  466. PROCEDURE ProcessFileMenu (  Item : INTEGER; VAR terminate : BOOLEAN );
  467.  BEGIN
  468.     CASE Item OF
  469.  
  470.       mfload  : ProcessLoadRequest                             |
  471.  
  472.       mfsave : IF FileLoaded THEN
  473.                  IF SaveDegasFile(TheOutPicture) THEN
  474.                  END; (* if *)
  475.               ELSE
  476.                  dumi := ShowAlert('NO Picture loaded',1,1);
  477.               END;                                             |
  478.  
  479.       mfimage :  SaveImage( TheOutPicture,
  480.                             ThePictureImage );                 |
  481.  
  482.       mfquit : terminate := TRUE;                              |
  483.     ELSE
  484.     END ;
  485.  END ProcessFileMenu;
  486.  
  487.  
  488. PROCEDURE ProcessPrintMenu (  Item : INTEGER );
  489.  BEGIN
  490.    CASE Item OF
  491.      mpprint : IF FileLoaded THEN
  492.                   dumc := Graphics.graf_mouse(HourGlass, NIL);
  493.                   PrintHiResPicture( ThePictureImage,
  494.                                      ThePrintImage,
  495.                                      TheOutPicture.HiResPicture );
  496.                   dumc := Graphics.graf_mouse(Arrow, NIL);
  497.                ELSE
  498.                   dumi := ShowAlert('NO Picture loaded',1,1);
  499.                END;                     |
  500.  
  501.  
  502.      mpsize  : IF FileLoaded THEN
  503.                   DoImageDialog( ThePictureImage,
  504.                                  ThePrintImage );
  505.                   DisplayPicture( TheOutPicture.HiResPicture );
  506.                ELSE
  507.                   dumi := ShowAlert('NO Picture loaded',1,1);
  508.                END;                     |
  509.  
  510.    ELSE
  511.    END;
  512.  END ProcessPrintMenu;
  513.  
  514.  
  515. PROCEDURE ProcessPictureMenu ( Item : INTEGER );
  516.  BEGIN
  517.    CASE Item OF
  518.  
  519.       mpicpat  : IF FileLoaded THEN
  520.                    SetPalette;
  521.                    IF TheInPicture.resolution # HiRes THEN
  522.                       ModifyPrintPalette( TheInPicture,
  523.                                           TheOutPicture,
  524.                                           ThePrintPalette);
  525.                       DisplayPicture( TheOutPicture.HiResPicture );
  526.  
  527.                    ELSE
  528.                       dumi := ShowAlert('Hi-res picture, no palette',1,1);
  529.                    END;
  530.                  ELSE
  531.                     dumi := ShowAlert('NO Picture loaded',1,1);
  532.                  END;                     |
  533.  
  534.       mpiccnv  : IF FileLoaded THEN
  535.                     dumc := Graphics.graf_mouse(HourGlass, NIL);
  536.                     ConvertDegasToHiRes( TheInPicture,
  537.                                          TheOutPicture,
  538.                                          ThePrintPalette );
  539.                     dumc := Graphics.graf_mouse(Arrow, NIL);
  540.                  ELSE
  541.                     dumi := ShowAlert('NO Picture loaded',1,1);
  542.                  END;                     |
  543.  
  544.   ELSE
  545.   END; (* case *)
  546.  
  547.  END ProcessPictureMenu;
  548.  
  549.  
  550. PROCEDURE ProcessImageMenu ( Item : INTEGER );
  551.  BEGIN
  552.    CASE Item OF
  553.  
  554.       mimgsel  : IF FileLoaded THEN
  555.                       SelectImage;
  556.  
  557.                    ELSE
  558.                       dumi := ShowAlert('Hi-res picture, no palette',1,1);
  559.                    END;
  560.  
  561.   ELSE
  562.   END; (* case *)
  563.  
  564.  END ProcessImageMenu;
  565.  
  566.  
  567.  
  568. (*----------------------------------------------------------------------*)
  569. (*  Which menu item was selected... and action it...                    *)
  570. (*----------------------------------------------------------------------*)
  571. PROCEDURE SelectMenu( Menu, Item : INTEGER; VAR terminate : BOOLEAN );
  572.   BEGIN
  573.     CASE Menu OF
  574.       deskmenu : IF Item = mabout THEN
  575.                       DoAboutDialog(CVersionString) ;
  576.                       DisplayPicture( TheOutPicture.HiResPicture );
  577.                  ELSE
  578.                  END;
  579.                  dumc := menu_tnormal(MenuTreePtr, deskmenu, TRUE);    |
  580.  
  581.       filemenu : ProcessFileMenu( Item, terminate ) ;
  582.                  dumc := menu_tnormal(MenuTreePtr, filemenu, TRUE);    |
  583.  
  584.       prntmenu : ProcessPrintMenu( Item );
  585.                  dumc := menu_tnormal(MenuTreePtr, prntmenu, TRUE);    |
  586.  
  587.       picmenu :  ProcessPictureMenu( Item );
  588.                  dumc := menu_tnormal(MenuTreePtr, picmenu, TRUE);     |
  589.  
  590.       imgmenu :  ProcessImageMenu( Item );
  591.                  dumc := menu_tnormal(MenuTreePtr, imgmenu, TRUE);     |
  592.  
  593.       prtrmenu : ChangePrinterSelected( Item );
  594.                  dumc := menu_tnormal(MenuTreePtr, prtrmenu, TRUE);    |
  595.     ELSE
  596.     END ;
  597.   END SelectMenu ;
  598.  
  599.  
  600. (* ------------------------------------------------------------------- *)
  601. (*   This is the routine which decides what to do in response to a     *)
  602. (*   message from GEM. It is the main loop of the program.             *)
  603. (* ------------------------------------------------------------------- *)
  604.  
  605. PROCEDURE HandleEvents ; (* based on GEMDEM *)
  606. (* Handle resource events *)
  607. CONST
  608.   CMenuSelected = 10;
  609.   CWindowClosed = 22;
  610.   CWindowRedraw = 20;
  611.   CBeginUpdate  = 1;
  612.   CEndUpdate    = 0;
  613.   CKeyEvent     = 1;
  614.   CEscKey       = CARDINAL(011BH);
  615.   CButtonEvent  = 2;
  616.   CMessageEvent = 16;
  617.   CEventTypes   = CButtonEvent + CMessageEvent + CKeyEvent;
  618.   CNumClicks    = 1;
  619.   CLeftButton   = 1;
  620.   CButtonDown   = 1;
  621.  
  622. VAR
  623.   quit       : BOOLEAN;
  624.   result     : INTEGER ;
  625.   pipeBuff   : Event.Message ;
  626.   evres      : Event.EventSet;
  627.   WhichEvent : INTEGER;
  628.   MoX, MoY, MoButton, MokState, KReturn, BReturn : CARDINAL;
  629. BEGIN
  630.   quit := FALSE;
  631.   ShowMouse;
  632.   LOOP (* do until window closed *)
  633.     evres :=  Event.evnt_multi
  634.                             ( Event.EventSet(CEventTypes), CNumClicks,
  635.                               CLeftButton,
  636.                               CButtonDown,
  637.                               FALSE, 0, 0, 0, 0,
  638.                               FALSE, 0, 0, 0, 0,
  639.                               pipeBuff,
  640.                               LONGCARD(0),
  641.                               MoX, MoY, MoButton, MokState,
  642.                               KReturn, BReturn );
  643.     WhichEvent := INTEGER(evres);
  644.     dumc := Window.wind_update(CBeginUpdate); (* stop anymore messages *)
  645.     IF ( WhichEvent = CButtonEvent ) THEN
  646.        HandleButtonEvent( MoX, MoY, MoButton );
  647.  
  648.     ELSIF ( WhichEvent = CKeyEvent )
  649.      AND  ( KReturn = CEscKey ) THEN
  650.         HandleEscKeyEvent;
  651.  
  652.     ELSE
  653.      CASE CARDINAL(pipeBuff.MessageType) OF         (* message type *)
  654.          CMenuSelected   : SelectMenu( pipeBuff.Message[0],
  655.                                        pipeBuff.Message[1],
  656.                        quit);
  657.                                   IF quit THEN EXIT END;     |
  658.          CWindowClosed   : EXIT                       |
  659.          CWindowRedraw   :
  660.                     SetPalette;
  661.                     DisplayPicture( TheOutPicture.HiResPicture );
  662.                                                              |
  663.      ELSE
  664.      END; (* case *)
  665.  
  666.     END; (* if *)
  667.  
  668.     dumc := Window.wind_update(CEndUpdate); (* let user select other things *)
  669.  
  670.   END; (* loop *) ;
  671.   dumc := Window.wind_update(CEndUpdate); (* let user select other things *)
  672. END HandleEvents ;
  673.  
  674.  
  675.  
  676. (*----------------------------------------------------------------------*)
  677. (* Save the screen palette as we will be changing it...                 *)
  678. (*----------------------------------------------------------------------*)
  679. PROCEDURE SaveScreenPalette;
  680.   CONST MinusOne = INTEGER(-1);
  681.   VAR i : CARDINAL;
  682.   BEGIN
  683.     FOR i := 0 TO 15 DO ScreenPalette[i] :=
  684.                             setColor(CARDINAL(MinusOne), i); END;
  685.   END SaveScreenPalette;
  686.  
  687.  
  688. (*----------------------------------------------------------------------*)
  689. (* Restore screen palette before exiting, user will like that...        *)
  690. (*----------------------------------------------------------------------*)
  691. PROCEDURE RestoreScreenPalette;
  692.   VAR i,j : CARDINAL;
  693.   BEGIN
  694.     FOR i := 0 TO 15 DO j := setColor(ScreenPalette[i],i); END;
  695.   END RestoreScreenPalette;
  696.  
  697.  
  698. (* ----------------------------------------------------------------- *)
  699. (* Load resource file                                                *)
  700. (* ----------------------------------------------------------------- *)
  701. PROCEDURE InitResource() : BOOLEAN ; (* get resource and show menu *)
  702.   CONST
  703.     NoResourceMsg = 'Cannot find resource file |';
  704.   VAR
  705.     s : String;
  706.         
  707.   BEGIN
  708.     dumc := rsrc_load(CResourceFilename);
  709.     IF ( dumc = 0 ) THEN
  710.        Concat(NoResourceMsg,CResourceFilename,s);
  711.        dumi := ShowAlert(s,1,1);
  712.        RETURN(FALSE);
  713.     END;
  714.  
  715.     dumc := rsrc_gaddr( tree , menu, MenuTreePtr);
  716.     dumc := menu_bar( MenuTreePtr, TRUE );
  717.     RETURN(TRUE);
  718.   END InitResource;
  719.  
  720.  
  721.  
  722. (*----------------------------------------------------------------------*)
  723. (* Initialisation part of module, this runs the program...              *)
  724. (*----------------------------------------------------------------------*)
  725. BEGIN
  726.   LargestBlock := LONGCARD(50000);
  727.   MaxBlocks    := SHORT( Malloc(LONGCARD(-1)) DIV LargestBlock );
  728.  
  729.   SaveScreenPalette;
  730.  
  731.   SetPalette;
  732.  
  733.   SetPrinterToUse(EpsonLQ80);
  734.  
  735.   ClearPicture ( TheOutPicture);
  736.  
  737.   FileLoaded := FALSE;
  738.   ThePictureImage.Width  := 0;
  739.   ThePictureImage.Height := 0;
  740.  
  741.   StartApplication; (* sign on to GEM, open Virtual WS etc. *)
  742.   IF NOT InitResource() THEN HALT END;
  743.  
  744.   TheWindow := CreateAWindow(ComponentSet{NAME,CLOSE});
  745.   SetAWindowTitle(TheWindow, 'No Picture Loaded');
  746.  
  747.   OpenAWindow(TheWindow);
  748.   ClearAWindow(TheWindow);
  749.  
  750.   dumc := Graphics.graf_mouse(Arrow,NIL) ; (* put pointing mouse *)
  751.  
  752.   IF ScreenResolution = LowRes THEN
  753.      dumi := ShowAlert('Please Use MEDIUM Resolution',1,1)
  754.   ELSE
  755.      ProcessLoadRequest;
  756.      HandleEvents (* stay there until 'quit' message *)
  757.   END;
  758.  
  759.   CloseAWindow(TheWindow);
  760.   DeleteAWindow(TheWindow); 
  761.  
  762.   dumc := menu_bar(MenuTreePtr, FALSE); (* show original menu *)
  763.  
  764.   dumc := rsrc_free();
  765.  
  766.   RestoreScreenPalette;
  767.  
  768.   TerminateApplication;   (* sign off from GEM *)
  769.   Cleanup;
  770. END DegasConvert.
  771.  
  772.